package 追踪JVM所以线程情况;

import java.util.Arrays;
import java.util.concurrent.TimeUnit;

/**
 * @author wanyuxiang
 * @version 1.0
 * @project baobaostore
 * @create 2017-05-11 14:17
 * @desc 使用Thread.getAllStackTrace()方法获取虚拟机所有线程的stackTraceElement对象
 **/
public class Test {
    public static void innerMethod() {
        System.out.println("inner....");
    }

    public static void aa() {
        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        innerMethod();
    }

    public static void main(String[] args) {
        Thread t = new Thread(Test::aa);
        t.start();
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Thread.getAllStackTraces().forEach((k, v) -> {
            System.out.print("当前线程:" + k.getName());
            System.out.print("\t");
            Arrays.stream(v).forEach(e -> {
                System.out.print("值:" + e);
            });
            System.out.print("\n");
        });
    }
}
